import org.havi.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.ImageObserver;


import org.havi.ui.*;
import org.havi.ui.event.HEventGroup;

import javax.tv.xlet.*;


public class Prueba5 extends HComponent implements Xlet,KeyListener {

	private static final long serialVersionUID = 1L;
	XletContext contexto;
	HScene scene =null;
	KeyEvent boton;
	HStaticText hstTexto;
	int x1=0,x2=-150,x3=0,x4=0;
	Image imagen,imagen1;
	HStaticIcon imag,imag1;
	private HStaticText labelHello;
	

	public void initXlet(XletContext contexto) throws XletStateChangeException {
		 int x=0,y=0;
		// Seta o Contexto e Scene
		this.contexto = contexto;
		this.scene = HSceneFactory.getInstance().getFullScreenScene(
		HScreen.getDefaultHScreen().getDefaultHGraphicsDevice());
		
		// Seta as propriedades no label
		//this.labelHello = new HStaticText("Mi Primer Ejemplo");
		//this.labelHello.setFont(new Font("Verdana", Font.BOLD, 30));
		//this.labelHello.setBounds(100,99, 300, 100);
		//this.labelHello.setForeground(Color.white);
		//this.labelHello.setBackground(new Color(0, 0, 0, 128));
		imagen = Toolkit.getDefaultToolkit().getImage("Pantalla2.jpg");
		//imagen1 = Toolkit.getDefaultToolkit().getImage("c.jpg");
		imag= new HStaticIcon(imagen, x1, x2, 700, 900);
		//imag1= new HStaticIcon(imagen1, x1, x2, 700, 900);
		
		x1++;
		x2++;
		// Adiciona o Label a Scene
		scene.setSize(700,976);
		
		//this.scene.add(this.labelHello);
		this.setSize(scene.getSize());
		scene.add(imag);
		//scene.add(imag1);
		scene.add(this);
		//this.scene.add(this.imagen);ool 
		scene.addKeyListener(this);

	}
	

	public void pauseXlet() {
		// TODO Auto-generated method stub
		
	}
   /* public void paint(Graphics g){
    	System.out.println("entre en el paint");
    	g.drawImage(imagen, 100,100, this);
    }*/
	public void startXlet() throws XletStateChangeException {
		// TODO Auto-generated method stub
		scene.setVisible(true);
		System.out.println("entre en start");
		scene.requestFocus();
		//System.out.println(boton.getKeyCode());
		
	}
	
	public void destroyXlet(boolean arg0) throws XletStateChangeException {
		// TODO Auto-generated method stub
	  HSceneFactory.getInstance().dispose(scene);
	  contexto.notifyDestroyed();
	}
	
	public void keyPressed(KeyEvent tecla) {
		// TODO Auto-generated method stub
		//boton azul key code = 406
		//boton amarillo key code = 405
		//boton verde key code = 404
		//boton verde key code = 403
		//boton arriba key code = 38
		//boton derecha key code = 39
		//boton abajo key code = 40
		//boton izquierda key code = 37
		//boton ok key code = 10
		
         System.out.println(tecla.getKeyCode());
		 if  (tecla.getKeyCode() == 403){
			//hstTexto.setForeground(new Color(0,0,250));
			//hstTexto.setBackground(new Color(0,0,255));
		    System.out.println("tecla 403");
		}  
		 if (tecla.getKeyCode() == 404){
		  	hstTexto.setForeground(new Color(255,0,255));
		 	 hstTexto.setBackground(new Color(255,0,255));
		 }
		 if (tecla.getKeyCode() == 405){
			hstTexto.setForeground(new Color(255,100,255));
			 hstTexto.setBackground(new Color(255,100,255));
		 }
		 if (tecla.getKeyCode() == 406){
			hstTexto.setForeground(new Color(0,255,255));
			 hstTexto.setBackground(new Color(0,255,255));
		 }
		  if (tecla.getKeyCode() == 38){
			  x2=x2-5;
			  hstTexto.setBounds(x1,x2,x3,x4);
			}  
		  if (tecla.getKeyCode() == 37){
			  x1=x1-5;
			  hstTexto.setBounds(x1,x2,x3,x4);
			}  
		  if (tecla.getKeyCode() == 39){
			  x1=x1+5;
			  hstTexto.setBounds(x1,x2,x3,x4);
			}  
		  if (tecla.getKeyCode() == 40){
			  x2=x2+5;
			  hstTexto.setBounds(x1,x2,x3,x4);
			} 
	  scene.repaint();
	}	
	

	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}



}
